package com.xiaoyu.lanling.feature.videomatch.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
import com.xiaoyu.base.app.App
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.BaseDialogFragment
import kotlinx.android.synthetic.main.av_funcitionality_time_limit_open_dialog.*

class AVFunctionalityTimeLimitOpenDialog : BaseDialogFragment() {

    companion object {
        const val PARAM_CONTENT = "key_content"
        val TAG = AVFunctionalityTimeLimitOpenDialog::class.simpleName

        fun show(content: String) {
            (App.getInstance().topActivity as? FragmentActivity)?.let {
                if (it.isFinishing || it.isDestroyed) {
                    return@let
                }

                val arguments = Bundle()
                arguments.putString(PARAM_CONTENT, content)

                val dialogFragment = (it.supportFragmentManager.findFragmentByTag(TAG) as? AVFunctionalityTimeLimitOpenDialog)
                        ?: AVFunctionalityTimeLimitOpenDialog()
                dialogFragment.arguments = arguments
                dialogFragment.setOnDismissListener(it as? OnDismissListener)
                dialogFragment.show(it.supportFragmentManager, TAG)
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogFullScreenDimStyle)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.av_funcitionality_time_limit_open_dialog, container, false)
    }

    override fun onViewCreatedSafelyAfterAppFinishInit(view: View, savedInstanceState: Bundle?) {
        super.onViewCreatedSafelyAfterAppFinishInit(view, savedInstanceState)
        initView()
        initBind()
    }

    private fun initBind() {
        arguments?.getString(PARAM_CONTENT)?.let {
            content.text = it
        }
        confirm.setOnClickListener { dismiss() }
        close_button.setOnClickListener { dismiss() }
    }

    private fun initView() {
    }
}